package thread.sync.lock;

public class CounterTest{
	 
	public static void main(String[] args) throws InterruptedException{
		Thread[] thread1 = new Thread[1000];
		Thread[] thread2 = new Thread[1000];
		Thread[] thread3 = new Thread[1000];
		
		SimpleCounter c1 = new SimpleCounter();
		SynchronizedCounter c2 = new SynchronizedCounter();
		LockCounter c3 = new LockCounter();
		
		for (int i=0; i < 1000; i++){
			thread1[i] = new Thread(c1);
			thread1[i].start();
			
			thread2[i] = new Thread(c2);
			thread2[i].start();
			
			thread3[i] = new Thread(c3);
			thread3[i].start();
			
		}
		
		for (int i=0; i < 1000; i++){
			thread1[i].join();
			thread2[i].join();
			thread3[i].join();
		}
		
		System.out.println("Counter -> Non Zeros : " + c1.count);
		System.out.println("Synchronized Counter -> Non Zeros : " + c2.count);
		System.out.println("Lock Counter -> Non Zeros : " + c3.count);
	}
}

// 1
/*
Counter -> Non Zeros : 1
Counter2 -> Non Zeros : 0
Counter3 -> Non Zeros : 0
*/

//2
/*
Counter -> Non Zeros : 0
Counter2 -> Non Zeros : 0
Counter3 -> Non Zeros : 0
*/


//3
/*
Counter -> Non Zeros : 8062
Counter2 -> Non Zeros : 0
Counter3 -> Non Zeros : 0
*/


//4
/*
Counter -> Non Zeros : 6349
Counter2 -> Non Zeros : 0
Counter3 -> Non Zeros : 0
*/


//5
/*
Counter -> Non Zeros : 0
Counter2 -> Non Zeros : 0
Counter3 -> Non Zeros : 0
*/


